//
//  MainViewController.swift
//  demo3
//
//  Created by hanweiguang on 2018/11/15.
//  Copyright © 2018年 hanweiguang. All rights reserved.
//

import UIKit

class MainViewController: UIViewController {

    fileprivate var instance: WXSDKInstance?
    fileprivate var weexView = UIView()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        navigationController?.setNavigationBarHidden(false, animated: false)
        self.view.backgroundColor = UIColor.lightGray
        title = "另一个weex"
        render()
 
    }
    
    override func viewWillAppear(_ animated: Bool) {
        navigationController?.setNavigationBarHidden(false, animated: false)

    }

    func render() {
        instance?.destroy()
        instance = WXSDKInstance()
        instance?.viewController = self
        instance?.frame = CGRect(origin: .zero, size: view.bounds.size)
        
        
        instance?.onCreate = { [unowned self] view in
            guard let v = view else { return }
            self.weexView.removeFromSuperview()
            self.weexView = v
            self.view.addSubview(self.weexView)
            UIAccessibility.post(notification: UIAccessibility.Notification.screenChanged, argument: v)
        }
        
        instance?.onFailed = { error in
            
        }
        
        instance?.renderFinish = { [weak self] view in
            
        }
        instance?.updateFinish = { view in
            
        }
        let jsURL = URL(string:"https://miniprogramf.applinzi.com/static/weex/demoa.weex")
        instance?.render(with: jsURL, options: ["bundleUrl":jsURL!], data: nil)
        WeexMap.shared.dictMap["homea"] = instance
        
//        WXSDKManager.store(<#T##instance: WXSDKInstance!##WXSDKInstance!#>, forID: <#T##String!#>)
    }

}
